<template>
  <view class="container">
    <view class="top-section">
	<h1><navigator url="/pages/index/login/login" open-type="navigate">
	<text>中国儿童银行</text>
			 </navigator></h1>
	<br/>
      <text>账户：{{name}}</text>
      <text>余额：{{balance}}元</text>
    </view>
    <view class="table-container">
      <uni-table>
        <thead>
          <uni-tr>
            <uni-th>序号</uni-th>
            <uni-th>类型</uni-th>
            <uni-th>金额</uni-th>
            <uni-th>余额</uni-th>
            <uni-th>日期</uni-th>
			<uni-th>备注</uni-th>
          </uni-tr>
        </thead>
        <tbody v-for="(recordItem, recordIndex) in bankRecords" :key="recordIndex">
          <!-- 在这里添加表格数据 -->
          <uni-tr>
            <uni-td>{{recordIndex+1}}</uni-td>
            <uni-td>{{ recordItem.type === 0 ? '取款' : (num === 1 ? '存款' : '')}}</uni-td>
            <uni-td>{{recordItem.money}}</uni-td>
            <uni-td>{{recordItem.balance}}</uni-td>
            <uni-td>{{recordItem.create_time}}</uni-td>
			<uni-td>{{recordItem.remark}}</uni-td>
          </uni-tr>
         
        </tbody>
      </uni-table>
	    <div style="display: flex; justify-content: center; margin-top: 20px;">
	           <button id="withdrawButton" @click="navigateToMethod('/pages/qukuan/qukuan')" style="background-color: #99f;">取款</button>
	           <button id="depositButton" @click="navigateToMethod('/pages/cunkuan/cunkuan')" style="background-color: #9f9;">存款</button>
	       </div>
    </view>
  </view>
</template>

<script>
export default {
	async onLoad(options) {
		this.id=options.id
		
	    // options 是一个对象，包含了传递过来的参数
	    // 在这里，可以通过 options.id 来获取传递的参数值
	    console.log(options.id); // 输出: 123
		
		
		let u=await this.$api.get(this.$api.prop().serviceUrl+"/common/model/queryById/?id="+this.id+"&modelName=User",{});
		this.balance=u.data.credit;
		this.name=u.data.username;
		let u2=await this.$api.get(this.$api.prop().serviceUrl+"/common/model/queryByFilter/?userid="+options.id+"&modelName=bankRecord",{});
		this.bankRecords=u2.data.items;
		debugger;
	  },
  data() {
    return {
		id:0,
		name:"",
		bankRecords:[],
		balance:0
	};
  },
  methods:{
  	navigateToMethod(url){
		
		uni.navigateTo({
				  
		  url: url+'?id='+this.id+'&name='+this.name
		});
		
  	}
  },
};
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20rpx;
}

.top-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40rpx;
}

.table-container {
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border: 1px solid #ccc;
  text-align: center;
  padding: 10rpx;
}

        #withdrawButton {
            background-color: red;
        }
        #depositButton {
            background-color: green;
        }
		
</style>
